﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using BusinessObjects.BO_GetObjects;
using LibraryO2S;
using Entity.StoreProcedure;
using BusinessObjects.BO_Actions.Members;
using System.Collections.Generic;

public partial class controls_admin_Members : Pages_Base
{
    protected void Page_Load(object sender, EventArgs e)
    {
        base.removeHGC(divMessage);
        if (!IsPostBack)
            loadMember();
    }
    private void loadMember()
    {
        DataTable objDT;
        if (Request["k_w"] != null)
            objDT = BO_Members.SearchLike(Request["k_w"].ToString(), base.Cur_page, base.Page_size, 1);
        else
            objDT = BO_Members.SelectWithPaged(base.Cur_page, base.Page_size, 1);
        if (!bindRepeater(rptMember, objDT, divMessage))
            if (Request["k_w"] != null)
                divMessage.InnerHtml = O2S_Message.Warning("Hệ Thống", "Không có bản ghi nào phù hợp với từ khóa: " + Request["k_w"].ToString() + "!");
    }
    protected void rptMember_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        try
        {
            Button btnMember = (Button)e.Item.FindControl("btnMember");
            int m_id = Convert.ToInt32(btnMember.CommandArgument);
            string commandName = e.CommandName;
            if (commandName.Equals("del"))
            {
                BO_Members.Delete(m_id);
                divMessage.InnerHtml = O2S_Message.Success("Thông Báo", "Xóa thành công .");
            }
            else if (commandName.Equals("active"))
                BO_Members.IsActive(m_id);
            else if (commandName.Equals("vip"))
                BO_Members.IsVip(m_id);
            loadMember();
        }
        catch (Exception ex)
        {
            divMessage.InnerHtml = O2S_Message.Error("Lỗi", "Phát hiện lỗi: <br />" + ex.Message);
        }
    }
    protected void rptMember_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        Button btnActive = (Button)e.Item.FindControl("btnActive");
        bool isactive = Convert.ToBoolean(btnActive.CommandArgument);
        if (!isactive)
            btnActive.CssClass = "icon-32-cancel";
        else
            btnActive.CssClass = "icon-32-checking";
        Button btnVip = (Button)e.Item.FindControl("btnVip");
        bool isVip = Convert.ToBoolean(btnVip.CommandArgument);
        if (!isVip)
            btnVip.CssClass = "icon-32-cancel";
        else
            btnVip.CssClass = "icon-32-checking";
    }
    protected void btnSearch_Click(object sender, EventArgs e)
    {
        base.search(txtKeyword.Text.Trim());
    }
    protected void btnDel_Click(object sender, EventArgs e)
    {
        string del_list = hdfCheck.Value;
        string[] sp_list = del_list.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
        BOMembers_Delete _action = new BOMembers_Delete();
        usp_Members_Delete _entity;
        List<usp_Members_Delete> _listData = new List<usp_Members_Delete>();
        foreach (string per in sp_list)
        {
            _entity = new usp_Members_Delete();
            _entity.MEMBER_ID = Convert.ToInt32(per);
            _listData.Add(_entity);
        }
        if (_action.ExecuteListDataAndReturnBooleanValue(_listData))
            divMessage.InnerHtml = O2S_Message.Success("Thông Báo", "Thực hiện thành công.");
        else
            divMessage.InnerHtml = O2S_Message.Error("Lỗi", "Chưa thực hiện được !");
        loadMember();
    }
}
